Resize by height
Asynchronously resizes an image to a specified height.
This feature resizes also the width of the image proportionally, without distorting it.
Syntax
resizeByHeight(image, heightPx)
Parameters
-
image :
HTMLImageElement
The image element to resize. -
heightPx :
number
The new height, in pixels, to resize the image to.
Return
- Promise :
Promise<HTMLImageElement>
A promise that resolves with the resized image element.
Throws
Error
Thrown if the specified height is negative or if there are errors during the resizing process.
Examples
const editpix = new EditPix();
// image url
const url = "images/img.jpg";
// create image
var image = new Image();
image.src = url;
//waiting image load
image.onload = () => {
// resize image by height
editpix.resizeByHeight(image, 100)
.then(resizedImage => {
// render modified image
document.body.appendChild(resizedImage)
})
.catch(error => { console.log(error) })
};